package es.mahulo.battleship.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;



/**
 * The player has got a name of identification, a board where to place the ships
 * and the list of shots he/she has already done.
 * 
 * @author mhuertas
 *
 */
@XmlRootElement


@Entity
@Table(name="PLAYER")
public class Player {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name="ID")
	private Long id;

	@OneToMany(targetEntity=Ship.class,mappedBy="player",fetch=FetchType.EAGER,cascade = {CascadeType.ALL })
	private List<Ship> ships;

	@OneToMany(targetEntity=Shot.class,mappedBy="player",fetch=FetchType.EAGER,cascade = {CascadeType.ALL })
	private List<Shot> shots;
	
	@ManyToOne
	@JoinColumn(name="ID_USER")	
	private User user;
	
	@ManyToOne
	@JoinColumn(name="ID_GAME")	
	private Game game;

	public Player() {
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public List<Ship> getShips() {
		return ships;
	}

	public void setShips(List<Ship> ships) {
		this.ships = ships;
	}

	public List<Shot> getShots() {
		return shots;
	}

	public void setShots(List<Shot> shots) {
		this.shots = shots;
	}

	@XmlTransient
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	@XmlTransient
	public Game getGame() {
		return game;
	}

	public void setGame(Game game) {
		this.game = game;
	}
	
	
	public String toString() {
		return "Player { Id: " 
				+ id 
				+ " user: " 
				+  user 
				+ " }";
	}

}

